#!/bin/bash

echo "🔍 实时查看Agent协商日志"
echo "=================================="

# 检查日志文件是否存在
if [ ! -f "agent_negotiation.log" ]; then
    echo "❌ 日志文件不存在，请先运行演示脚本"
    exit 1
fi

echo "📋 协商演示日志内容:"
echo "=================================="
cat agent_negotiation.log

echo ""
echo "=================================="
echo "📊 日志分析总结:"
echo "=================================="

# 统计关键事件
echo "🔢 关键事件统计:"
echo "  📡 API调用次数: $(grep -c "发送协作请求到" agent_negotiation.log)"
echo "  📥 响应接收次数: $(grep -c "收到响应" agent_negotiation.log)"
echo "  ✅ 成功协作次数: $(grep -c "协作分析完成" agent_negotiation.log)"
echo "  🤝 协商发起次数: $(grep -c "BudgetAgent发起协商" agent_negotiation.log)"
echo "  🎯 协商达成次数: $(grep -c "达成协商共识" agent_negotiation.log)"

echo ""
echo "📝 详细决策过程:"
echo "=================================="

# 显示WeatherAgent的分析结果
echo "🌤️ WeatherAgent分析结果:"
grep -A 20 "WeatherAgent协作分析完成" agent_negotiation.log | head -25

echo ""
echo "🤝 协商过程详情:"
grep -A 10 "协商请求:" agent_negotiation.log | head -15

echo ""
echo "✅ 最终协商结果:"
grep -A 10 "最终协商结果:" agent_negotiation.log | head -15

echo ""
echo "💡 提示: 日志文件保存在 agent_negotiation.log"
echo "   可以使用 'tail -f agent_negotiation.log' 实时查看新日志"
